<template>
  <van-icon
   :color="value ? '#3296fa': '#777'"
   :name=" value ? 'star':'star-o'"
   @click="onCollect"/>
</template>

<script>
import { addConllectArticle, delConllectArticle } from '@/api/article.js'
import { Toast } from 'vant'
export default {
  name: 'collectArcitle',
  props: {
    value: {
      type: Boolean,
      require: true
    },
    artId: {
      type: [String, Object, Number],
      require: true
    }
  },
  data () {
    return {

    }
  },

  created () {

  },

  methods: {
    async   onCollect () {
      Toast.loading({
        message: '加载中...',
        forbidClick: true
      })
      try {
        if (this.value) {
        // 已收藏 做取消收藏
          await delConllectArticle(this.artId)
        } else {
          await addConllectArticle(this.artId)
        }
        Toast.success('加载成功')
      } catch (err) {
        console.log(err)
        Toast.fail('加载失败')
      }
    }
  }
}
</script>

<style scoped lang='less'>

</style>
